package com.tz.crm.service.impl;


import com.tz.crm.dao.NormalLogDao;
import com.tz.crm.entity.NormalLog;
import com.tz.crm.service.NormalLogService;
import com.tz.crm.utils.Pager;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by WK on 2017/2/15.
 * 显示正常日志分页查询后的页面
 */
@Service
@Transactional
public class NormalLogServiceImpl extends BaseServiceImpl<NormalLog, String> implements NormalLogService {

    @Autowired
    private NormalLogDao normalLogDao;

/*   private static final Logger LOGGER= Logger.getLogger(NormalLogServiceImpl.class);*/


    /**
     * @param normalLog normalLog
     * @param pager     pager
     * @return 分页后的界面
     */
    @Override
    @SuppressWarnings("unchecked")
    public Pager<NormalLog> getByPager(NormalLog normalLog, Pager pager) {
        if (normalLog == null) {
            normalLog = new NormalLog();
        }
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(NormalLog.class);
        if (StringUtils.isNotBlank(normalLog.getMethodName())) {
            detachedCriteria.add(Restrictions.like("methodName", normalLog.getMethodName()).ignoreCase());
        }
        pager = normalLogDao.findByPager(pager, detachedCriteria, Order.asc("methodName"));
        return pager;
    }

}
